package com.leetcode;

import com.leetcode.common.ListNode;

/**
 * 234. 回文链表
 * 递归
 *
 * @author fy
 * @date 2022/4/11 21:38
 */
public class Solution234_1 {

    private ListNode frontPointer;

    public boolean isPalindrome(ListNode head) {
        frontPointer = head;
        return recursivelyCheck(head);
    }

    private boolean recursivelyCheck(ListNode currentNode) {
        if (currentNode != null) {
            if (!recursivelyCheck(currentNode.next)) {
                return false;
            }
            if (currentNode.val != frontPointer.val) {
                return false;
            }
            frontPointer = frontPointer.next;
        }
        return true;
    }

}
